﻿-- Author      : Kurapica
-- Create Date : 6/27/2008

--[[
The naming space of IGAS and version check.
In this system, each file register a key to mark it's version.It's used for version check.
--]]
do
	-- This file don't make version check,only load once.
	if IGAS and type(IGAS) == "table" then
		return
	end
	
	------------------------------------------------------
	------------------- Naming Space ---------------------
	------------------------------------------------------
	IGAS = {}
	IGAS_DB = {}

	------------------------------------------------------
	----------------- RegisterFunction System --------------------
	------------------------------------------------------    
	local _metaF = {
		__index = {
			["RegisterFunction"] = function(self, name, func)
				assert(name and func and type(name)=="string" and type(func)=="function")
				
				self[name] = func
			end,
		},
	
		__newindex = function(_table,_key,_value)
            if _key == "RegisterFunction" then
			    error("This key is read-only", 2)
            end
            
            rawset(_table,_key,_value)
		end,
	}
    
	setmetatable(IGAS, _metaF)
	
	-- Some useful function
	--- Print Function
	IGAS:RegisterFunction("Print", function(self, ...)
		local msg = ""
		if( DEFAULT_CHAT_FRAME ) then
			for i = 1, select('#', ...) do
				if msg ~= "" then msg = msg.."," end
				msg = msg..tostring(select(i, ...))
				end
			DEFAULT_CHAT_FRAME:AddMessage(msg)
		end
	end)
	
	--- RegisterFile Function
	local _RegisterFile = {}
	IGAS:RegisterFunction("RegisterFile", function(self, _key, _version)
		if _RegisterFile[_key] and _RegisterFile[_key] >= _version then
			return false
		else
			_RegisterFile[_key] = _version
			return true
		end
	end)
end
